#include <iostream>
using namespace std;
#include <cstring>
#include<string>
//面向对象的特性：封装，继承，多态

class Animal
{
public:
    virtual void speak()//虚函数就是被virtual修饰的成员函数
    {
        cout <<"Animal::speak()"<<endl;
    }

    virtual void run()
    {
        cout<<"Animal::run()"<<endl;
    }

private:
    int m_age;
};

class Cow:public Animal
{
public:
    void speak()
    {
        cout <<"cow::speak() mou mou mou "<<endl;
    }

    void run()
    {
        cout<<"cow::run() mou mou mou "<<endl;
    }
private:
    char m_color[24];
};

class Horse:public Animal
{
public:
    void speak()
    {
        cout <<"Horse::speak() lv lv lv "<<endl;
    }

    void run()
    {
        cout<<"Horse::run() lv lv lv "<<endl;
    }
private:
    char m_type[20];
};
class CowHorse:public Animal
{
public:
    void speak()
    {
        cout <<"CowHorse::speak() 好的 "<<endl;
    }

    void run()
    {
        cout<<"CowHorse::run() 收到 "<<endl;
    }

};
int main()
{
#if 0
    Animal ani;

    ani.speak();
    ani.run();

    Cow cow;
    cow.speak();
    cow.run();

    Horse horse;
    horse.speak();
    horse.run();
#endif

#if 1
    /*多态的使用*/
    /*父类指针指向子类对象*/
    Animal * ani1 = new Cow;
    /*父类指针调用重写成员函数*/
    ani1->speak();
    Animal *ani2 = new Horse;
    ani2->speak();

#endif 
    return 0;
}